<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="referrer" content="no-referrer" />
    <title>{$active.name}-参加报名</title>
    {include file='default/public/header'/}
    <style type="text/css">
        body,.weui-cell{ background: #f5f5f5;}
    </style>
</head>
<body >

<div class="page-group">
    <div class="page">
        <div class="content">
            <nav class="bar bar-tab" style="height:0;top: 0;">
                {include file='default/public/fixed'/}
            </nav>
            {include file='default/public/nav'/}
            <article class="weui-article">
                <section>
                    <form id="form1">
                        <div class="weui-cells weui-cells_form"  style="margin-top: 0;">
                            {foreach $active.act_field as $vo}
                            {switch name="vo.type" }
                            {case value="images"}
                            <div class="weui-cell image-cell">
                                <div class="weui-cell__bd">
                                    <div class="weui-uploader">
                                        <div class="weui-uploader__hd">
                                            <div class="weui-uploader__title">{$vo.name}</div>
                                        </div>
                                        <div class="weui-uploader__bd">
                                            <ul class="weui-uploader__files" id="images" data-name="{$vo.name}">
                                                {if condition="$participant.images"}
                                                {foreach $participant.images as $vo}
                                                <li class="weui-uploader__file"><img src="{$vo}" width="100%" height="100%"/></li>
                                                {/foreach}
                                                {/if}
                                            </ul>
                                            {if condition="empty($participant) || $participant.status == 2"}
                                            <div class="weui-uploader__input-box images_box">
                                            </div>
                                            {/if}
                                        </div>
                                    </div>
                                </div>
                            </div>
                            {/case}
                            {case value="nickname"}
                            <div class="weui-cell" >
                                <div class="weui-cell__hd"><label class="weui-label">{$vo.name}</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" type="text" placeholder="{$vo.name}" name="nickname" value="{$participant.nickname}" id="nickname"  data-name="{$vo.name}"/>
                                </div>
                                <div class="weui-cell__ft">

                                </div>
                            </div>
                            {/case}
                            {case value="shop_name"}
                            <div class="weui-cell" >
                                <div class="weui-cell__hd"><label class="weui-label">{$vo.name}</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" type="text" placeholder="{$vo.name}" name="shop_name" value="{$participant.shop_name}" id="shop_name"  data-name="{$vo.name}"/>
                                </div>
                                <div class="weui-cell__ft">

                                </div>
                            </div>
                            {/case}
                            {case value="shop_address"}
                            <div class="weui-cell" >
                                <div class="weui-cell__hd"><label class="weui-label">{$vo.name}</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" type="text" placeholder="{$vo.name}" name="shop_address" value="{$participant.shop_address}" id="shop_address"  data-name="{$vo.name}"/>
                                </div>
                                <div class="weui-cell__ft">

                                </div>
                            </div>
                            {/case}
                            {case value="shop_introduction"}
                            <div class="weui-cell" >
                                <div class="weui-cell__hd"><label class="weui-label">{$vo.name}</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" type="text" placeholder="{$vo.name}" name="shop_introduction" value="{$participant.shop_introduction}" id="shop_introduction"  data-name="{$vo.name}"/>
                                </div>
                                <div class="weui-cell__ft">

                                </div>
                            </div>
                            {/case}
                            {case value="birthday"}
                            <div class="weui-cell" >
                                <div class="weui-cell__hd"><label class="weui-label">{$vo.name}</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" type="date" placeholder="{$vo.name}" name="birthday" value="{$participant.birthday}" id="birthday"  data-name="{$vo.name}"/>
                                </div>
                                <div class="weui-cell__ft">

                                </div>
                            </div>
                            {/case}
                            {case value="gender"}
                            <div class="weui-cell" >
                                <div class="weui-cell__hd"><label class="weui-label">{$vo.name}</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" type="text" placeholder="{$vo.name}" name="gender"
                                           value="{if condition='$participant.gender == 1'}男{elseif condition='$participant.gender == 2'}女{else/}{/if}"
                                           data-values="{$participant.gender}"
                                           id="gender" data-name="{$vo.name}"/>
                                </div>
                                <div class="weui-cell__ft">

                                </div>
                            </div>
                            {/case}
                            {case value="mobile"}
                            <div class="weui-cell" >
                                <div class="weui-cell__hd"><label class="weui-label">{$vo.name}</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" type="text" placeholder="{$vo.name}" name="mobile" value="{$participant.mobile}" id="mobile" data-name="{$vo.name}"/>
                                </div>
                                <div class="weui-cell__ft">

                                </div>
                            </div>
                            {/case}
                            {case value="xuanyan"}
                            <div class="weui-cell">
                                <div class="weui-cell__bd">
                                    <textarea class="weui-textarea" placeholder="请输入{$vo.name}" name="xuanyan" rows="3"
                                              id="xuanyan" style="background: #f5f5f5;"  data-name="{$vo.name}">{$participant.xuanyan}</textarea>
                                </div>
                            </div>
                            {/case}
                            {default /}
                            {/switch}
                            {/foreach}
                            {if condition="$participant.status ==2 && $participant.no_pass_intro"}
                            <div class="weui-cell">
                                <div class="weui-cell__bd">
                                    <textarea class="weui-textarea"  rows="3" readonly style="background: #f5f5f5;color:red;">未通过原因:{$participant.no_pass_intro}</textarea>
                                </div>
                            </div>
                            {/if}
                            {switch name="$participant.status"}
                            {case value="0"}
                            <div class="item">
                                <div class="detail-btn" style="background: #ababab;">待 审 核</div>
                            </div>
                            {/case}
                            {case value="1"}
                            <div class="item">
                                <div class="detail-btn" >已 报 名</div>
                            </div>
                            {/case}
                            {case value="2"}
                            <div class="item" style="background: #f5f5f5;">
                                <div class="form-btn" style="background: #ababab;">审 核 未 通 过</div>
                                <span style="font-size: 12px;color:#929292;">请重新上传照片后点击按钮再次报名</span>
                            </div>
                            {/case}
                            {default /}
                            <div class="item">
                                <div class="form-btn" style="background: {$active.theme_color};">报 名</div>
                            </div>
                            {/switch}
                        </div>
                    </form>
                </section>
            </article>
        </div>
    </div>
</div>
{include file='default/public/js'/}
<script type="text/javascript">

    var birthday,gender,nickname,shop_name,shop_address,shop_introduction,mobile,xuanyan,images=[];
    $('.form-btn').click(function(){
        if(CheckForm()){
            $.ajax({
                url:'{:url("do_sign_up")}',
                type:'post',
                data:{'id':'{$id}','nickname':nickname,'mobile':mobile,'birthday':birthday,'xuanyan':xuanyan,'shop_name':shop_name,'shop_address':shop_address,'shop_introduction':shop_introduction,'imgs':images,'gender':gender},
                dataType:'json',
                success:function(data){
                    if(data.code == 0){
                        location.href = '{:url("detail",["id"=>$id])}'
                    }else{
                        $.alert(data.message);
                    }
                }
            });
        }
    });

    $('.detail-btn').click(function(){
        location.href = '{:url("detail",["id"=>$id])}';
    });

    $("#gender").select({
        title: "选择性别",
        items: [
            {
                title: "男",
                value: 1
            },
            {
                title: "女",
                value: 2
            }
        ]
    });

    function CheckForm(){
        $('.weui-cell').removeClass('weui-cell_warn');
        $('.weui-cell__ft').html('');

        var $u_images = $('#images');
        if($u_images.length > 0 ){
            if(images.length == 0){
                $.alert($('#images').attr('data-name')+'不能为空');
                $('.image-cell').addClass('weui-cell_warn');
                return false;
            }
        }

        var $nickname = $('#nickname');
        if($nickname.length > 0 ){
            nickname = $nickname.val();
            if(nickname == ''){
                $.alert($nickname.attr('data-name')+'不能为空');
                $nickname.parents('.weui-cell').addClass('weui-cell_warn');
                $nickname.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        var $birthday = $('#birthday');
        if($birthday.length > 0 ){
            birthday = $birthday.val();
            if(birthday == ''){
                $.alert($birthday.attr('data-name')+'不能为空');
                $birthday.parents('.weui-cell').addClass('weui-cell_warn');
                $birthday.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        var $gender = $('#gender');
        if($gender.length > 0 ){
            gender = $gender.attr('data-values');
            if(gender == ''){
                $.alert($gender.attr('data-name')+'不能为空');
                $gender.parents('.weui-cell').addClass('weui-cell_warn');
                $gender.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        var $mobile = $('#mobile');
        if($mobile.length > 0 ){
            mobile = $mobile.val();
            if(mobile == ''){
                $.alert($mobile.attr('data-name')+'不能为空');
                $mobile.parents('.weui-cell').addClass('weui-cell_warn');
                $mobile.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
            var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\d{8})$/;
            if(!myreg.test(mobile))
            {
                $.alert('请输入有效的手机号码！');
                $mobile.parents('.weui-cell').addClass('weui-cell_warn');
                $mobile.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        var $xuanyan = $('#xuanyan');
        if($xuanyan.length > 0 ){
            xuanyan = $xuanyan.val();
            if(xuanyan == ''){
                $.alert($xuanyan.attr('data-name')+'不能为空');
                $xuanyan.parents('.weui-cell').addClass('weui-cell_warn');
                $xuanyan.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        var $shop_address = $('#shop_address');
        if($shop_address.length > 0 ){
            shop_address = $shop_address.val();
            if(shop_address == ''){
                $.alert($shop_address.attr('data-name')+'不能为空');
                $shop_address.parents('.weui-cell').addClass('weui-cell_warn');
                $shop_address.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        var $shop_introduction = $('#shop_introduction');
        if($shop_introduction.length > 0 ){
            shop_introduction = $shop_introduction.val();
            if(shop_introduction == ''){
                $.alert($shop_introduction.attr('data-name')+'不能为空');
                $shop_introduction.parents('.weui-cell').addClass('weui-cell_warn');
                $shop_introduction.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        var $shop_name = $('#shop_name');
        if($shop_name.length > 0 ){
            shop_name = $shop_name.val();
            if(shop_name == ''){
                $.alert($shop_name.attr('data-name')+'不能为空');
                $shop_name.parents('.weui-cell').addClass('weui-cell_warn');
                $shop_name.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        return true;
    }

    var image_number = 0;
    var max_number = 1;
    var error_code = '{$error_code?:0}',error_message = '{$error_message?:""}';
    var has_cover = 0 , is_tip = 0;
    $('.images_box').click(function(){
        if(error_code != '0'){
            if(error_code != '98'){
                $.alert(error_message);
                return false;
            }else{
                mag.toLogin(function(rs){
                    window.location.href = '{:url("index",["id"=>$active.id])}?token='+rs.token;
                });
            }
            return false;
        }
        if(images.length != 0){
            $.confirm("是否重新上传作品", function() {
                has_cover = 0;
                is_tip = 0;
                images = [];
                $('#images').html('');
                set_image();
            }, function() {
                return false;
            });
        }else{
            set_image();
        }

    });

    function set_image(){
        mag.picPick({
            preview: function (res) {
                image_number++;
                if (image_number > max_number) {
                    image_uploader = false;
                    $.alert('图片最多只能上传' + max_number + '张');
                    return false;
                } else {
                    $('#images').append('<li class="weui-uploader__file"><img src="'+res.data+'" width="100%" height="100%"/></li>');
                }
            },
            success: function (res) {
                if (images.length >= max_number) {
                    $.alert('图片最多只能上传' + max_number + '张');
                    return false;
                } else {
                    images.push('{$site}/core/attachment/attachment/attach?aid=' + res.aid);
                }
            },
            fail: function (res) {
                $.alert('图片'+res.key+'上传失败');
            }
        });
    }
    
    

</script>
<script src='http://app.lxh.magcloud.cc/public/static/dest/js/libs/magjs-x.js'></script>
<script type="text/javascript">
    mag.setData({
        shareData: {
            title: '{$active.share_info.title}',
            des: '{$active.share_info.intro}',
            picurl: '{$active.share_info.img}',
            linkurl: '{$active.share_info.url}'
        }
    });
</script>
</body>
</html>
